import java.util.Stack;

public class MinStack {

        Stack<Integer> stack1;
        Stack<Integer> stack2;
        public MinStack() {
            stack1 = new Stack<>();
            stack2 = new Stack<>();
        }

        public void push(int val) {
            stack1.push(val);
            if(stack2.isEmpty()){
                stack2.push(val);
                return;
            }
            int x = stack2.peek();
            if(x >= val){
                stack2.push(val);
            }
        }

        public void pop() {
            if(stack1.isEmpty()){
                return;
            }
            if(stack1.peek().equals(stack2.peek())){
                stack1.pop();
                stack2.pop();
            }else{
                stack1.pop();
            }
        }

        public int top() {
            if(stack1.isEmpty()){
                return -1;
            }
            return stack1.peek();
        }

        public int getMin() {
            if(stack1.isEmpty()){
                return -1;
            }
            return stack2.peek();
        }
    }


